<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>指令模板管理</title>
    <#include "/common/resource.ftl">
    <script type="text/javascript">
        var getSearchParams = function(){
            return {
            	searchInput:$("input[name='searchInput']").val() || "",
            };
        }
    </script>
</head>
<body class="bg-gray">

   <div class="ui-operation">
       <div class="ui-buttons">
   		 <div class="layui-btn-group tools">
            <button class="layui-btn layui-btn-normal open-dialog" p="url:'${params.contextPath}/view/icip/instruction/instruction_template_edit.htm',title:'添加数据上报模板',width:'800px',height:'95%'">
				<i class="fa fa-plus"></i>添加
			</button>
			<button class="layui-btn layui-btn-normal singleSelected" p="url:'${params.contextPath}/view/icip/instruction/instruction_template_edit.htm',title:'编辑数据上报模板',width:'800px',height:'95%'">
				<i class="fa fa-pencil"></i>修改
			</button>
			<button class="layui-btn layui-btn-normal remove-button" reurl="${params.contextPath}/web/instructionTemplate/delete.json">
				<i class="fa fa-remove"></i>删除
			</button>
			<button class="layui-btn layui-btn-normal  accept-button" reurl="${params.contextPath}/web/instructionTemplate/accpet.json">
				<i class="fa fa-play"></i>启用
			</button>
			<button class="layui-btn layui-btn-normal  stop-button" reurl="${params.contextPath}/web/instructionTemplate/stop.json">
				<i class="fa fa-stop"></i>停用
			</button>
         </div>   
         <div class="ui-searchs">
             <div class="value" style="">
             
                 <input type="text" name="searchInput" placeholder="模板名称  排序号">
             </div>
             <input type="button" value="搜索" class="layui-btn layui-btn-danger search-button"/>
         </div>
       </div>
   </div>
   <div class="ui-content" style="padding-left: 10px;padding-right:10px;">
       <table id="datagrid" options="url:'${params.contextPath}/web/instructionTemplate/page.json',params:'getSearchParams',dblClickRow:'showDetail'">
			<thead>
               	<tr>
               	   <th data-options="field:'ck',checkbox:true"></th>
                   <th data-options="field:'name',width:80">模板名称</th>
                  
                   <th data-options="field:'orderNum',width:60">排序号</th>
                   <th data-options="field:'stateStr',width:40,formatter:formatState">状态</th>
                   <th data-options="field:'createTimeStr',width:150,align:'center'">创建时间</th>
                   <th data-options="field:'remark',width:200">说明</th>
				</tr>
			</thead>
       </table>
   </div>
   
</body>
<script type="text/javascript">

$(function(){
	
	$(".accept-button").click(function() {
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择启用模板")
			return false;
		}
		var url = $(this).attr("reurl");
		$.ajaxRequest({
			url : url,
			data : {
				ids : ids.join(",")
			},
			success : function(data) {
				$.message(data.message);
				if (data.success) {
					DataGrid.reload();
				}
			}
		});
	});
	
	$(".stop-button").click(function(){
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择停用模板")
			return false;
		}
		var url = $(this).attr("reurl");
		$.ajaxRequest({
			url : url,
			data : {
				ids : ids.join(",")
			},
			success : function(data) {
				$.message(data.message);
				if (data.success) {
					DataGrid.reload();
				}
			}
		});
	});
	
	
	$(".remove-button").click(function() {
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择删除记录")
			return false;
		}
		var url = $(this).attr("reurl");
		layer.confirm('确定删除记录', function() {
			$.ajaxRequest({
				url : url,
				data : {
					ids : ids.join(",")
				},
				success : function(data) {
					$.message(data.message);
					if (data.success) {
						DataGrid.reload();
					}
				}
			});
		});
	});
	
	 
    
});
function formatCycle(val, row){
	return '每月28号上报';
}
function formatState(val, row){
    if (row.state == 1) {
        return '<span class="ui-accept">' + val + '</span>';
    } else if(row.state == 2){
    	return '<span class="ui-stop">' + val + '</span>';
    }
    return val;
}
function showDetail (index, row) {
    var url = "${params.contextPath}/view/icip/datareport/datareport_template_detail.htm?id=" + row.id;
    DialogManager.openDialog("url:'" + url + "',title:'模板详情',width:'800px',height:'450px'");
};
</script>
</html>
